package sis.uitest;/*
* @auther 顶风少年 
* @mail dfsn19970313@foxmail.com
* @date 2019-08-04 21:22
* @notify 
* @version 1.0
*/

import junit.framework.TestCase;
import sis.ui.Util;

import javax.swing.*;
import java.awt.*;

public class UtilTest extends TestCase {
    private JPanel panel;

    protected void setUp(){
        panel = new JPanel();
    }

    //测试不存在的组件
    public void testNotFound(){
        assertNull(Util.getComponent(panel,"abc"));
    }

    //测试单层组件
    public void testDirectlyEmbeddedComponent(){
        final String name = "a";
        Component component = new JLabel("x");
        component.setName(name);
        panel.add(component);
        assertEquals(component,Util.getComponent(panel,name));
    }

    //测试嵌套组件
    public void testSubComponent(){
        //创建一个组件 设置内容和名字
        final String name = "a";
        Component component = new JLabel("x");
        component.setName(name);

        //在创建一个组件,将上一个添加到当前组件,形成一个嵌套组件
        JPanel subpanel = new JPanel();
        subpanel.add(component);
        JPanel subpane2 = new JPanel();

        panel.add(subpane2);
        panel.add(subpanel);
        assertEquals(component,Util.getComponent(panel,name));
    }
}
